package com.dbq.share;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;

import com.facebook.CallbackManager;
import com.facebook.FacebookCallback;
import com.facebook.FacebookException;
import com.facebook.share.Sharer;
import com.facebook.share.model.ShareLinkContent;
import com.facebook.share.widget.ShareDialog;

/**
 * Created by sunkai on 2017/12/27.
 */

public class FacebookAssistActivity extends BaseAssistActivity {
    private CallbackManager callbackManager;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        callbackManager = CallbackManager.Factory.create();
    }

    @Override
    protected void appNotInstallTips() {

    }

    @Override
    protected boolean appInstall() {
        return true;
    }

    @Override
    protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        callbackManager.onActivityResult(requestCode, resultCode, data);
    }

    @Override
    protected void sendMessage() {
        startShare();
        ShareLinkContent content = new ShareLinkContent.Builder()
                .setContentUrl(Uri.parse(shareWebPage.url))
                .setQuote(shareWebPage.title)
                .build();
        ShareDialog shareDialog = new ShareDialog(this);
        shareDialog.registerCallback(callbackManager, new FacebookCallback<Sharer.Result>() {
            @Override
            public void onSuccess(Sharer.Result result) {
                shareSuccess();
                finish();
            }

            @Override
            public void onCancel() {
                shareCancel();
                finish();
            }

            @Override
            public void onError(FacebookException error) {
                finish();
                shareError(error.toString());
            }
        });
        shareDialog.show(content);
    }


}
